<?php

include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';

class Refactoring_Div_New_Tag extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";
      $mount_tree = new Mount_DOM_tree();

      $search = $domDocument->getElementsByTagName('div');

      foreach ($search as $f) {
         /* <div id=“header”> <div id=“cabecalho”> */
         if (ereg("^header$", strtolower($f->getAttribute('id'))) || ereg("^cabecalho$", strtolower($f->getAttribute('id')))) {
            $answer = '&LT;header&GT; ... &LT;/header&GT;';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer);
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "header", 1));
         }

         /* <div id=“menu”> ou <div id=“nav”> */
         if (ereg("^menu$", strtolower($f->getAttribute('id'))) || ereg("^nav$", strtolower($f->getAttribute('id')))) {
            $answer = '&LT;nav&GT; ... &LT;/nav&GT;';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer);
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "nav", 1));
         }

         /* <div id = “content”> ou <div id = “conteudo”> */
         if (ereg("^content$", strtolower($f->getAttribute('id'))) || ereg("^conteudo$", strtolower($f->getAttribute('id')))) {
            $answer = '&LT;article&GT; ... &LT;/article&GT;';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer);
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "article", 1));
         }

         /* <div id=“sidebar”> ou <div id=“side-content”> ou <div id=“lateral”> ou <div id=“conteudo-lateral”> */
         if (ereg("^sidebar$", strtolower($f->getAttribute('id'))) || ereg("^side-content$", strtolower($f->getAttribute('id'))) ||
                 ereg("^lateral$", strtolower($f->getAttribute('id'))) || ereg("^conteudo-lateral$", strtolower($f->getAttribute('id')))) {
            $answer = '&LT;aside&GT; ... &LT;/aside&GT;';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer);
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "aside", 1));
         }

         /* <div id=“footer”> ou <div id=“rodape”> */
         if (ereg("^footer$", strtolower($f->getAttribute('id'))) || ereg("^rodape$", strtolower($f->getAttribute('id')))) {
            $answer = '&LT;footer&GT; ... &LT;/footer&GT;';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer);
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "footer", 1));
         }
      }

      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Substituir &LT;div&GT; que estruturam o documento HTML pelas novas tags") . $result;
      }

      return $result;
   }

}

?>
